//-----------------------------------------------------------------------

// <copyright file="CheckBoxFieldDefinition.cs" company="Jamie Knight">

// Copyright (c) Jamie Knight. All rights reserved.

// </copyright>

//-----------------------------------------------------------------------

using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;

namespace DevKnightlie.WPF.AutoForm.FieldDefinitions
{
    /// <summary>
    /// Field definition class for a checkbox
    /// </summary>
    public class CheckBoxFieldDefinition : BaseFieldDefinition
    {
        #region Private Fields

        private bool _integralLabel = true;

        #endregion

        #region Properties

        /// <summary>
        /// Sets or returns a value indicating whether the field title should be within the checkbox or in a separate Label control
        /// </summary>
        public bool IntegralLabel
        {
            get { return _integralLabel; }
            set { _integralLabel = value; }
        }

        #endregion

        #region Methods

        public override void BuildInputControl()
        {
            CheckBox checkBox = new CheckBox()
            {
                VerticalContentAlignment = System.Windows.VerticalAlignment.Center,
                HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left,
                Content = IntegralLabel ? Title : ""
            };
            Binding checkBoxBinding = new Binding(PropertyName);
            BindingOperations.SetBinding(checkBox, ToggleButton.IsCheckedProperty, checkBoxBinding);
            SetupEnabledBinding(checkBox);
            ContainerControl = InputControl = checkBox;
        }



        public override void BuildLabelControl()
        {
            if (IntegralLabel)
            {
                LabelControl = null;
            }
            else
            {
                base.BuildLabelControl();
            }
        }

        #endregion

    }
}
